package authoriz

import (
	"github.com/gin-gonic/gin"
	"github.com/morphyguo/demo/web/blog/pkg/app"
	"net/http"
	"strings"
)

var authmap = make(map[string]bool)

func Auth() gin.HandlerFunc {
	return func(c *gin.Context) {
		if strings.HasPrefix(c.Request.RequestURI, "/api/") {
			c.JSON(http.StatusUnauthorized, app.Response{
				Code: 401,
				Msg:  "权限问题",
				Data: nil,
			})
			c.Abort()
		}
		c.Next()
	}
}

func init() {
	authmap["api/"] = true
}
